package com.zerowidth.db.op;

import com.zerowidth.db.DBHelper;
import com.zerowidth.db.base.SqlResult;
import com.zerowidth.db.bean.ProblemBean;
import com.zerowidth.db.utils.IOUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ProblemDB {

    public static List<ProblemBean> getProblemList() {
        String sql = String.format("SELECT * FROM problem where status = 1");

        SqlResult sr = DBHelper.executeQueryEx(sql);

        try {
            ResultSet rs = sr.rs;
            List<ProblemBean> vipEnumBeanList = new ArrayList<>();
            while (rs.next()) {
                ProblemBean bean = new ProblemBean();
                bean.title = rs.getString("title");
                bean.image_url = rs.getString("image_url");
                bean.answer = rs.getString("answer");
                bean.create_time = rs.getString("create_time");
                bean.status = rs.getInt("status");

                vipEnumBeanList.add(bean);
            }

            return vipEnumBeanList;
        } catch (SQLException sqlException) {
            sqlException.printStackTrace();
        } finally {
            IOUtils.close(sr);
        }

        return null;
    }

}
